package com.example.myi18n.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Locale;

@RestController
@RequestMapping("/home")
public class HomeController {

    @Autowired
    private MessageSource ms;

    @GetMapping("/sayHi")
    public String sayHi(String locale) {
        Locale l = null;
        if(locale.equals("en") ){
            l = Locale.US;
        }else if(locale.equals("zh")){
            l = Locale.CHINA;
        }
        
        return ms.getMessage("welcome.h1",null, l);
    }

    @GetMapping("/")
    public String kkk(){
        return "kkk";
    }
}
